using System;

using LocalBoard.Domain;
using LocalBoard.Controller;

namespace LocalBoard.Web
{
	public class BoardPage : DefaultClubPage
	{
		private Board _currentBoard = null;
		public Board CurrentBoard
		{
			get
			{
				if(_currentBoard == null)
					_currentBoard = this.ClubController.GetBoard(BoardController.BoardId);
				return _currentBoard;
			}
		}
		public string CurrentBoardPageUrl
		{
			get {return ClubPage.AddBoardQueryStringToUrl(ClubPage.AddClubQueryStringToUrl(Request.Url.AbsolutePath, this.Club.Id), BoardController.BoardId);}
		}
//		private BoardController _boardController = null;
		public override BoardController BoardController
		{
			get
			{
				if(ClubController != null)
					return new BoardController(GetCurrentBoardId(), ClubController, GetCurrentPageNo(), Global.AccessorFactory);
				return null;
			}
		}

		override protected void OnInit(EventArgs e)
		{
			base.OnInit(e);
		}

		#region Private helper
		protected int GetCurrentBoardId()
		{
			try
			{
				return Convert.ToInt32(Request.Params["board"]);
			}
			catch
			{
				return 0;
			}
		}
		#endregion
	}
}